<script setup>
import { useRoute, useRouter } from 'vue-router'
import { getToken, setToken, removeToken } from '@/utils/auth'
import { getLogin } from "../../api/charge/webview"
import { watch } from "vue"
const route = useRoute();
const router = useRouter()
const goToExternalPage = (token) => {
  if(!token) return;
  getLogin({ token }).then(response => {
    if (response.code == 200 && response.token) {
      setToken(response.token)
      router.push("/index")
    }else{
      proxy.$modal.msgError(response.msg);
      setTimeout(() => {
        router.push("/login")
      }, 2000);
    }
  }).catch(err=>{
      setTimeout(() => {
        router.push("/login")
      }, 2000);
  })
};



watch(() => route.query.token, newValue => {
  goToExternalPage(newValue)
}, { deep: true, immediate: true })



</script>

<template>
  <div></div>
</template>
